inviteMemberTeam
Email Templatesโ
New User Template (addNewMemberTeam)
| Existing User Template (addOtherMemberTeam)
|
- ๐ฌ๐ง English
- ๐ฎ๐น Italiano
Function Name: inviteMemberTeam
Author: Domenico Cerone Creation Date: 13/10/2025
Last Reviewer: Domenico Cerone
Trigger: HTTPS (onRequest)
Purpose: Sends invitation emails to team members using a provided email address, with different templates based on whether the user already exists in Firebase Authentication or needs to complete registration.
Detailed Functionalityโ
This Firebase Function performs the following operations in sequence:
1. Environment Detectionโ
- Determines the current environment (staging/production) from the service account
- Checks database URL and project ID to identify the correct environment
- Sets the appropriate base URL for email links
2. Team Data Retrievalโ
- Receives
teamIdandemailas input parameters - Queries the
Teamscollection to retrieve team document - Extracts team name from the
nameproperty - Uses the provided email parameter directly for profile lookup
- Validates team existence and data integrity
3. Profile Data Enrichmentโ
- Retrieves profile data from the
Profilescollection using the provided email - Constructs full name from
firstNameandlastNamefields - Falls back to formatted username from email if profile data is incomplete
4. Notification Preference Checkโ
- Checks if the user has enabled the inviteMemberTeam notification in their notification preferences
- Verifies
notification_types.inviteMemberTeamfield in the profile - If notification is disabled (false): returns success without sending email
- If notification is enabled (true): proceeds with user authentication check
- Provides clear logging about notification preference status
5. User Authentication Checkโ
- Checks if the user exists in Firebase Authentication using the email
- Uses
admin.auth().getUserByEmail()to verify user existence - Determines which email template to use based on user status
6. Email Template Selection and Sendingโ
For New Users (not in Firebase Auth):
- Uses template:
bd525131-a5a9-11f0-95cc-e23f717f7d6f - Generates JWT security token valid for 7 days
- Includes registration completion link with token
- Template variables:
profile: Full name of recipientnameTeam: Team nameurl: Base URL for environmenttoken: JWT security token
For Existing Users (already in Firebase Auth):
- Uses template:
a25db440-a5e1-11f0-95cc-e23f717f7d6f - Simple notification email without token
- Template variables:
profile: Full name of recipientnameTeam: Team name
7. JWT Token Generation (New Users Only)โ
- Creates JWT token with the following payload:
email: User's email addressteamId: Team identifierteamName: Team nameinvitedAt: Invitation timestamp
- Token expires after 7 days
- Uses secret key:
ARShades_Studio_Secret_Key_Invite_Token_Security
8. Email Configurationโ
- Sender: no-reply@arshades.com (ARShades Studio)
- Service: ZeptoMail with template system
- Region: europe-central2
- CORS: Enabled for cross-origin requests
9. Environment-Specific URLsโ
- Production: studio.arshades
- Staging: stagingstudio.arshades
- Automatically detected based on Firebase project configuration
The function ensures that team members receive appropriate invitation emails based on their current status in the system, facilitating smooth onboarding for new users and simple notifications for existing users.
Input (Payload):โ
{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}
Required Parameters:
teamId(string): The ID of the team document in the Teams collectionemail(string): The email address of the user to invite to the team
Output (Success):โ
{
"success": true,
"teamId": "AijTPF2JbKz2c6SxW0uo",
"teamName": "Development Team",
"recipientEmail": "newmember@arshades.com",
"recipientName": "John Doe",
"environment": "staging",
"baseUrl": "stagingstudio.arshades",
"userExists": false,
"templateUsed": "new_user",
"tokenGenerated": true,
"message": "Email di invito inviata con successo con token di sicurezza (valido 7 giorni)"
}
Output (Error):โ
{
"success": false,
"error": "Team con ID AijTPF2JbKz2c6SxW0uo non trovato",
"teamId": "AijTPF2JbKz2c6SxW0uo"
}
Testingโ
URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam
Test with Emulator:
- Start the Firebase emulator:
firebase emulators:start --only functions - Ensure you're using Node.js version 20:
nvm use 20 - Test with curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam" \
-H "Content-Type: application/json" \
-d '{"teamId": "AijTPF2JbKz2c6SxW0uo", "email": "user@example.com"}'
Postman Testing:
- Method: POST
- URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam
- Headers: Content-Type: application/json
- Body (raw JSON):
{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}
Deploy Command:โ
firebase deploy --only functions:inviteMemberTeam
Production URL:โ
Live Function: https://europe-central2-arshades-7e18a.cloudfunctions.net/inviteMemberTeam
This function is called via HTTP POST request with the teamId parameter.
Function Name: inviteMemberTeam
Autore: Domenico Cerone Data di creazione: 13/10/2025
Last Reviewer: Domenico Cerone
Trigger: HTTPS (onRequest)
Purpose: Invia email di invito ai membri del team utilizzando un indirizzo email fornito, con template diversi in base al fatto che l'utente esista giร in Firebase Authentication o debba completare la registrazione.
Funzionamento Dettagliatoโ
Questa Firebase Function esegue le seguenti operazioni in sequenza:
1. Rilevamento dell'Ambienteโ
- Determina l'ambiente corrente (staging/produzione) dal service account
- Controlla l'URL del database e il project ID per identificare l'ambiente corretto
- Imposta l'URL base appropriato per i link nelle email
2. Recupero Dati del Teamโ
- Riceve
teamIdedemailcome parametri di input - Interroga la collezione
Teamsper recuperare il documento del team - Estrae il nome del team dalla proprietร
name - Utilizza direttamente il parametro email fornito per la ricerca del profilo
- Valida l'esistenza del team e l'integritร dei dati
3. Arricchimento Dati del Profiloโ
- Recupera i dati del profilo dalla collezione
Profilesusando l'email fornita - Costruisce il nome completo dai campi
firstNameelastName - Utilizza come fallback il nome utente formattato dall'email se i dati del profilo sono incompleti
4. Controllo Preferenze Notificheโ
- Controlla se l'utente ha abilitato inviteMemberTeam nelle sue preferenze di notifica
- Verifica il campo
notification_types.inviteMemberTeamnel profilo - Se la notifica รจ disabilitata (false): restituisce successo senza inviare email
- Se la notifica รจ abilitata (true): procede con il controllo autenticazione utente
- Fornisce logging chiaro sullo stato delle preferenze di notifica
5. Controllo Autenticazione Utenteโ
- Controlla se l'utente esiste in Firebase Authentication usando l'email
- Utilizza
admin.auth().getUserByEmail()per verificare l'esistenza dell'utente - Determina quale template email utilizzare in base allo stato dell'utente
6. Selezione Template Email e Invioโ
Per Nuovi Utenti (non in Firebase Auth):
- Utilizza template:
bd525131-a5a9-11f0-95cc-e23f717f7d6f - Genera token JWT di sicurezza valido per 7 giorni
- Include link per completamento registrazione con token
- Variabili template:
profile: Nome completo del destinatarionameTeam: Nome del teamurl: URL base per l'ambientetoken: Token JWT di sicurezza
Per Utenti Esistenti (giร in Firebase Auth):
- Utilizza template:
a25db440-a5e1-11f0-95cc-e23f717f7d6f - Email di notifica semplice senza token
- Variabili template:
profile: Nome completo del destinatarionameTeam: Nome del team
7. Generazione Token JWT (Solo Nuovi Utenti)โ
- Crea token JWT con il seguente payload:
email: Indirizzo email dell'utenteteamId: Identificatore del teamteamName: Nome del teaminvitedAt: Timestamp dell'invito
- Il token scade dopo 7 giorni
- Utilizza chiave segreta:
ARShades_Studio_Secret_Key_Invite_Token_Security
8. Configurazione Emailโ
- Mittente: no-reply@arshades.com (ARShades Studio)
- Servizio: ZeptoMail con sistema di template
- Regione: europe-central2
- CORS: Abilitato per richieste cross-origin
9. URL Specifici per Ambienteโ
- Produzione: studio.arshades
- Staging: stagingstudio.arshades
- Rilevati automaticamente in base alla configurazione del progetto Firebase
La funzione garantisce che i membri del team ricevano email di invito appropriate in base al loro stato attuale nel sistema, facilitando un onboarding fluido per i nuovi utenti e semplici notifiche per gli utenti esistenti.
Input (Payload):โ
{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}
Parametri Richiesti:
teamId(string): L'ID del documento del team nella collezione Teamsemail(string): L'indirizzo email dell'utente da invitare nel team
Output (Success):โ
{
"success": true,
"teamId": "AijTPF2JbKz2c6SxW0uo",
"teamName": "Development Team",
"recipientEmail": "newmember@arshades.com",
"recipientName": "John Doe",
"environment": "staging",
"baseUrl": "stagingstudio.arshades",
"userExists": false,
"templateUsed": "new_user",
"tokenGenerated": true,
"message": "Email di invito inviata con successo con token di sicurezza (valido 7 giorni)"
}
Output (Error):โ
{
"success": false,
"error": "Team con ID AijTPF2JbKz2c6SxW0uo non trovato",
"teamId": "AijTPF2JbKz2c6SxW0uo"
}
Testingโ
URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam
Test with Emulator:
- Avviare l'emulatore Firebase:
firebase emulators:start --only functions - Assicurarsi di usare Node.js versione 20:
nvm use 20 - Testare con curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam" \
-H "Content-Type: application/json" \
-d '{"teamId": "AijTPF2JbKz2c6SxW0uo", "email": "user@example.com"}'
Postman Testing:
- Metodo: POST
- URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam
- Headers: Content-Type: application/json
- Body (raw JSON):
{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}
Deploy Command:โ
firebase deploy --only functions:inviteMemberTeam
URL di Produzione:โ
Funzione Live: https://europe-central2-arshades-7e18a.cloudfunctions.net/inviteMemberTeam
Questa funzione viene chiamata tramite richiesta HTTP POST con i parametri teamId ed email.

